package leetcode;

/**
 * @Project : AlgorithmLearning
 * @Package : Leetcode
 * @File : Q0518.java
 * @Author : WangRuoyu
 * @Date 2023/11/24 22:34
 */

public class Q0518 {
    //    /*** 多重背包 二维数组 ***/
//    public int change(int amount, int[] coins) {
//        int[][] f = new int[coins.length + 1][amount + 1];
//        f[0][0] = 1;
//        for (int i = 1; i <= coins.length; i++) {
//            for (int j = 0; j <= amount; j++) {
//                f[i][j] = f[i - 1][j];
//                if (j >= coins[i - 1]) f[i][j] += f[i][j - coins[i - 1]];
//            }
//        }
//        return f[coins.length][amount];
//    }

    /*** 多重背包 一维数组 ***/
    public int change(int amount, int[] coins) {
        int[] f = new int[amount + 1];
        f[0] = 1;
        for (int i = 1; i <= coins.length; i++) {
            for (int j = coins[i - 1]; j <= amount; j++) {
                f[j] += f[j - coins[i - 1]];
            }
        }
        return f[amount];
    }

    public static void main(String[] args) {
        Q0518 sl = new Q0518();
    }
}